package com.xingfly.web;

import com.xingfly.model.Notification;
import com.xingfly.model.User;
import com.xingfly.security.jwt.annotation.CurrentUser;
import com.xingfly.service.NotificationService;
import com.xingfly.util.Type;
import com.xingfly.web.model.ResponseModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by SuperS on 03/01/2017.
 */
@RestController
@RequestMapping("notifies")
public class NotificationController {
    @Autowired
    private NotificationService notificationService;

    @GetMapping("count")
    public ResponseModel<?> allCount(@CurrentUser User user) {
        return ResponseModel.ok(notificationService.getNotificationsCount(user.getId()));
    }


    @GetMapping
    public ResponseModel<?> all(@CurrentUser User user) {
        List<Notification> notifications = new ArrayList<Notification>();
        notifications.addAll(notificationService.getNotifications(user.getId(), Type.NOTIFY_TYPE_COMMENT));
        notifications.addAll(notificationService.getNotifications(user.getId(), Type.NOTIFY_TYPE_FOLLOW));
        notifications.addAll(notificationService.getNotifications(user.getId(), Type.NOTIFY_TYPE_LIKE));
        return ResponseModel.ok(notifications);
    }

    @GetMapping("/comment")
    public ResponseModel<?> myComment(@CurrentUser User user) {
        return ResponseModel.ok(notificationService.getNotifications(user.getId(), Type.NOTIFY_TYPE_COMMENT));
    }

    @GetMapping("/like")
    public ResponseModel<?> myLike(@CurrentUser User user) {
        return ResponseModel.ok(notificationService.getNotifications(user.getId(), Type.NOTIFY_TYPE_LIKE));
    }

    @GetMapping("/follow")
    public ResponseModel<?> myFollow(@CurrentUser User user) {
        return ResponseModel.ok(notificationService.getNotifications(user.getId(), Type.NOTIFY_TYPE_FOLLOW));
    }


}
